<?php
namespace Portal\Controller;
use Common\Controller\HomebaseController;

class ListController extends HomebaseController {
	//文章列表   2017年2月24日16:02:51   liuzm	
	public function index(){
		$where['post_status']=1;
		
		$count=M('posts')->where($where)->count();
		$page = $this->page($count, 1);
		$list=M('posts')->where($where)->limit($page->firstRow , $page->listRows)->select();
		$this->assign('list',$list);
		$this->assign("page", $page->show('List'));
		$this->display(":list");
	}
	
	/**
	 * 
	 * {@inheritDoc}
	 * @see \Common\Controller\AppframeController::page()
	 */
	protected function page($total_size = 1, $page_size = 0, $current_page = 1, $listRows = 6, $pageParam = '', $pageLink = '', $static = false) {
		if ($page_size == 0) {
			$page_size = C("PAGE_LISTROWS");
		}

		if (empty($pageParam)) {
			$pageParam = C("VAR_PAGE");
		}

		$page = new \Page($total_size, $page_size, $current_page, $listRows, $pageParam, $pageLink, $static);
        $page->SetPager('Admin', '{first}{prev}&nbsp;{liststart}{list}&nbsp;{next}{last}<span>共{recordcount}条数据</span>', array("listlong" => "4", "first" => "首页", "last" => "尾页", "prev" => "上一页", "next" => "下一页", "list" => "*", "disabledclass" => ""));
		return $page;
	}

	// 前台文章列表
//	public function index() {
//	    $term_id=I('get.id',0,'intval');
//		$term=sp_get_term($term_id);
//		if(empty($term)){
//		    header('HTTP/1.1 404 Not Found');
//		    header('Status:404 Not Found');
//		    if(sp_template_file_exists(MODULE_NAME."/404")){
//		        $this->display(":404");
//		    }
//		    return;
//		}
//		$tplname=$term["list_tpl"];
//  	$tplname=sp_get_apphome_tpl($tplname, "list");
//  	$this->assign($term);
//  	$this->assign('cat_id', $term_id);
//  	$this->display(":$tplname");
//	}
//	
//	// 文章分类列表接口,返回文章分类列表,用于后台导航编辑添加
//	public function nav_index(){
//		$navcatname="文章分类";
//      $term_obj= M("Terms");
//      $where=array();
//      $where['status'] = array('eq',1);
//      $terms=$term_obj->field('term_id,name,parent')->where($where)->order('term_id')->select();
//		$datas=$terms;
//		$navrule = array(
//		    "id"=>'term_id',
//          "action" => "Portal/List/index",
//          "param" => array(
//              "id" => "term_id"
//          ),
//          "label" => "name",
//		    "parentid"=>'parent'
//      );
//		return sp_get_nav4admin($navcatname,$datas,$navrule) ;
//	}
}
